package tacticalLayer.tactics;

import org.jdom.Element;

import planninglanguage.plans.BasicOperatorPlan;
import util.XMLWriter;
import base.WargusGameState;

abstract public class Tactic {
	int m_unitID;
	
	
	public Tactic(int unitID) {
		m_unitID = unitID;
	}
	
	/*
	 * Returns the tactic to be executed in the next cycle ("null" means end of tactic)
	 */
	public Tactic cycle(WargusGameState gameState) {
		return null;
	}
	
	public BasicOperatorPlan getGoal() {
		return null;
	}
	
	public int getUnitID() {
		return m_unitID;
	}
	
	abstract public void writeXML(XMLWriter w);
	public static Tactic loadFromXML(Element e) {
		assert e.getName().equals("tactic") :
			"ScriptedTacticalLayer.loadFromXML: Invalid XML Element " +
			e.getName();
		
		Tactic t = null;
		
		// Could switch this to the loading method of Condition.java as long
		// as we aren't dependent on the type names staying the way they are now..
		String type = e.getAttributeValue("type");
		if (type.equals("attack")) {
			t = AttackTactic.loadTacticFromXML(e);
		} else if (type.equals("build")) {
			t = BuildTactic.loadTacticFromXML(e);
		} else if (type.equals("default")) {
			t = DefaultTactic.loadTacticFromXML(e);
		} else if (type.equals("empty")) {
			t = EmptyTactic.loadTacticFromXML(e);
		} else if (type.equals("idle")) {
			t = IdleTactic.loadTacticFromXML(e);
		} else {
			throw new Error("Tactic.loadFromXML: unknown plan type '" + type + "'");
		}
		
		return t; 
	}
}
